import Vue from 'vue'
import App from './App.vue'
import "./assets/style/reset.css"
import "./assets/style/global.css"
import router from "./routes";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'



import store from "./store";
import {message} from "./utils/message";
import qs from "qs";

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(mavonEditor);

// 设置标题
router.beforeEach((to, from, next) => {
  if(to.meta.title){
    document.title = to.meta.title;
  }
  next();
});

// 页面加载事件
async function loading(){
  // 页面加载检验登录态
  await store.dispatch("user/validLogin");
  // 页面加载获取用户信息
  if(store.state.user.isLogin){
    await store.dispatch("user/getInfo", {fields: "email,avatar,nickname"});
  }
}
loading();

Vue.prototype.$msg = message;
Vue.prototype.$qs = qs;

new Vue({
  render: h => h(App),
  router,
  store,
}).$mount('#app');
